<template>
  <t-modal :title="title" :width="640" :visible="visible" :confirmLoading="loading" @ok="() => { $emit('ok'); }"
    @cancel="() => { $emit('cancel'); }">
    <a-spin :spinning="loading">
      <a-form :form="form">
        <a-row :gutter="16">
          <a-form-item class="hiddenItem">
            <!-- uuid隐藏 -->
            <a-input v-decorator="['uuid']" disabled type="hidden" />
          </a-form-item>
          <a-col class="gutter-row" :span="24">
            <a-form-item :label="'名称'" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入名称" v-decorator="[
                'classificationName',
                { rules: [{ required: true, message: '必填' }] },
              ]" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="24">
            <a-form-item label="编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入编码" v-decorator="[
                'classificationCode',
                { rules: [{ required: true, message: '必填' }] },
              ]" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="24">
            <a-form-item :label="'排序'" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number placeholder="请输入排序" v-decorator="[
                'classificationSort',
                { rules: [{ required: true, message: '必填' }] },
              ]" :min="1" :max="100" />
            </a-form-item>
          </a-col>
          <a-col class="gutter-row" :span="24">
            <a-form-item :label="$ct('remarks', '备注')" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea :rows="4" v-decorator="['classificationRemake']" placeholder="请输入备注" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </t-modal>
</template>

<script>
import pick from "lodash.pick";

import TreeSelect from "@/components/TopVUI/custom/TreeSelect";
// 表单字段
const fields = [
  "uuid",
  "classificationName",
  "classificationCode",
  "classificationStatus",
  "classificationRemake",
  "classificationSort",
];

export default {
  components: {
    TreeSelect,
  },
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
    type: {
      type: String,
    },
  },
  data() {
    return {
      title: "",
      labelCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 5,
        },
      },
      wrapperCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 15,
        },
      },
      form: this.$form.createForm(this),
    };
  },
  methods: {
    add(m, data) {
    },
    edit(m, data) {
    },
  },
  created() {
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v));
    // 当 model 发生改变时，为表单设置值
    this.$watch("model", () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields));
    });
  },
};
</script>
